<?php
/**
 * My new Zend Framework project
 * 
 * @author  
 * @version 
 */
define('ROOT_DIR', dirname(dirname(__FILE__)));
set_include_path('.' . PATH_SEPARATOR . '../library' . PATH_SEPARATOR . './application/default/models/' . PATH_SEPARATOR . get_include_path());
require_once 'Zend/Controller/Front.php';
require_once 'Zend/Loader.php';
require_once 'Zend/Layout.php';
require_once 'Zend/Config/Ini.php';
//Cargar clases necesarias
Zend_Loader::loadClass('Zend_Registry');
Zend_Loader::loadClass('Zend_Db');
Zend_Loader::loadClass('Zend_Db_Table');
Zend_Loader::loadClass('Zend_Auth');
Zend_Loader::loadClass('Zend_Translate');
Zend_Loader::loadClass('Zend_Cache');

/**
 * Archivo de configuracion
 */
/*$dbconfig = new Zend_Config_Ini('./application/config.ini', 'Database');
$db = Zend_Db::factory($dbconfig->adapter, $dbconfig->db->config->toArray());
Zend_Db_Table::setDefaultAdapter($db);
Zend_Registry::set('dbAdapter', $db);*/
$siteconfig = new Zend_Config_Ini(ROOT_DIR.'/application/config.ini', 'SiteInfo');
Zend_Registry::set('siteInfo', $siteconfig->site->info);

/**
 * Carga del MVC para las vistas
 */
$mvcOptions = $siteconfig->site->layout->toArray();
$mvcOptions['layoutPath'] = ROOT_DIR . $mvcOptions['layoutPath'];
$layout = Zend_Layout::startMvc($mvcOptions);

/**
 * Objeto para las traducciones
 */
$translate = new Zend_Translate('csv', ROOT_DIR . '/lang/' . $siteconfig->site->info->langdefault . '/general.csv', $siteconfig->site->info->langdefault);
Zend_Registry::set('translate', $translate);
/**
 * Cache del sitio
 */
$frontendOptions = array(
			'lifetime' => 7200,
			'debug_header' => false,
			'default_options' => array(
					'cache' => true,
					'cache_with_get_variables' => true
			),
			'regexps' => array('/*' => array('cache' => true))
);
$backendOptions = array('cache_dir' => ROOT_DIR.'/tmp/cache');
/**
 * Setup controller
 */
$controller = Zend_Controller_Front::getInstance();
$controller->setControllerDirectory('../application/default/controllers');
$controller->throwExceptions(false); // should be turned on in development time 

try{
	$cache = Zend_Cache::factory('Page', 'File', $frontendOptions, $backendOptions);
	//Inicializo el cache
	//$cache->start();
	// run!
	$controller->dispatch();
}catch (Exception $e){
	echo "Mensaje: ".$e->getMessage();
}
